<?php
###
#  Baing PHP 框架 1.0.0
#  http://baing.co/
#
#  Copyright: 白晓阳
#  License: CC BY-NC-SA 4.0
#  https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh
###

namespace bai\resource\document;


class Download extends \bai\resource\Document
{
    public const TYPE_DEFAULT = '';
    public const RESOURCE_DEFAULT = 'resource';

    public function run()
    {
        $path = $this->find('path');
        $filename = basename($path);
        self::$response->addHeader('Content-Type', 'application/octet-stream');
        self::$response->addHeader('Content-Length', filesize($path));
        self::$response->addHeader('Content-Disposition', "attachment; filename={$filename}");
        return parent::run();
    }
}